<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        img {
            vertical-align: top;
        }

        #slider {
            width: 750px;
            height: 320px;
            border: 1px solid #ccc;
            padding: 10px;
            margin: 100px auto;
            position: relative;
        }

        #top {
            width: 100%;
            height: 100%;
            position: relative;
            overflow: hidden;
        }

        #top ul {
            position: absolute;
            left: 0;
            top: 0;
        }

        #top ul li {
            width: 750px;
            height: 320px;
            float: left;
        }

        #slider ol {
            position: absolute;
            right: 10px;
            bottom: 10px;
        }

        #slider ol li {
            width: 20px;
            height: 20px;
            background-color: darkgray;
            display: inline-block;
            margin-right: 3px;
            border-radius: 50%;
            cursor: pointer;
        }

        #slider ol li.current {
            background-color: orangered;
        }
    </style>
</head>
<body>
<div id="slider">
    <div id="top">
        <ul id="ul">
            <li><img src="imgs/pic01.jpg" alt=""></li>
            <li><img src="imgs/pic02.jpg" alt=""></li>
            <li><img src="imgs/pic03.jpg" alt=""></li>
            <li><img src="imgs/pic04.jpg" alt=""></li>
            <li><img src="imgs/pic05.jpg" alt=""></li>
        </ul>
    </div>
    <ol id="ol">
    </ol>
</div>
<script src="js/myFunc.js"></script>
<script>
    window.onload = function () {
        // 1. 获取需要的标签
        var lis = $("ul").children;
        var currentIndex = 0, indicatorIndex = 0;

        // 2. 克隆li标签
        $("ul").appendChild(lis[0].cloneNode(true));

        // 3. 动态创建页码
        for (var i = 0; i < lis.length - 1; i++) {
            var li = document.createElement("li");
            $("ol").appendChild(li);
        }

        // 4. 第一个选中
        $("ol").children[0].className = "current";

        // 5.鼠标进入圆点
        var olLis = $("ol").children;
        for (var j = 0; j < olLis.length; j++) {
            (function (j) {
                // 5.1 获取单独的li标签
                var li = olLis[j];

                // 5.2 鼠标进入
                li.onmouseover = function () {
                    for (var i = 0; i < olLis.length; i++) {
                        olLis[i].className = "";
                    }

                    this.className = "current";

                    // 5.3 动起来
                    constant($("ul"), -(750 * j), 100);
                    currentIndex = indicatorIndex = j;
                };
            })(j);
        }

        // 6.自动轮播
        var timer = setInterval(autoPlay, 1000);

        // 7. 清除和设置定时器
        $("slider").onmouseover = function () {
            clearInterval(timer);
        };

        $("slider").onmouseout = function () {
            timer = setInterval(autoPlay, 1000);
        };

        function autoPlay() {
            // 6.1 ul滚起来
            currentIndex++;
            if (currentIndex > lis.length - 1) {
                $("ul").style.left = 0;
                currentIndex = 1;
            }
            constant($("ul"), -currentIndex * 750, 100);

            // 6.2 指示器滚起来
            indicatorIndex++;
            if (indicatorIndex > olLis.length - 1) {
                indicatorIndex = 0;
            }
            for (var i = 0; i < olLis.length; i++) {
                olLis[i].className = "";
            }

            olLis[indicatorIndex].className = "current";

        }
    }
</script>
</body>
</html>